package zelix.gui.clickguis.caesium;

import java.awt.Color;
import java.util.HashMap;

import zelix.Core;
import zelix.gui.clickguis.caesium.components.Frame;
import zelix.gui.clickguis.caesium.components.GuiButton;
import zelix.gui.clickguis.caesium.components.GuiFrame;
import zelix.gui.clickguis.caesium.listeners.ClickListener;
import zelix.gui.clickguis.caesium.listeners.ComponentsListener;
import zelix.gui.clickguis.caesium.util.FramePosition;
import zelix.hack.Hack;
import zelix.hack.HackCategory;
import zelix.utils.resourceloader.Strings;
import zelix.utils.Wrapper;
import net.minecraft.client.gui.FontRenderer;


/**
 * @author sendQueue <Vinii>
 *
 *         Further info at Vinii.de or github@vinii.de, file created at 11.11.2020. 
 *         Use is only authorized if given credit!
 * 
 * 		   Some renderstuff requires https://github.com/sendQueue/LWJGLUtil
 * 
 */
public class Panel extends ClickGui {
	public static HashMap<String, FramePosition> framePositions = new HashMap<String, FramePosition>();

	public static FontRenderer fR = Wrapper.INSTANCE.fontRenderer();

	public static String theme;
	
	public static int FRAME_WIDTH = 100;
	
	// colors
	public static int color = new Color(193, 105, 170, 220).getRGB();
	public static int fontColor = Color.white.getRGB();
	public static int grey40_240 = new Color(40, 40, 40, 140).getRGB();
	public static int black195 = new Color(0, 0, 0, 195).getRGB();
	public static int black100 = new Color(0, 0, 0, 100).getRGB();
	
	
	/**
	 * Initializes Panel
	 * 
	 * @param theme
	 * @param fontSize
	 */
	public Panel(String theme, int fontSize) {
		this.theme = theme;
		//fR = new FontRenderer("BigNoodleTitling", fontSize);
	}

	@Override
	public void initGui() {
		int x = 25;
		int n =0;
		for (HackCategory cat : HackCategory.values()) {
			GuiFrame frame;
			// load frame positions
			if (framePositions.containsKey(cat.name())) {
				FramePosition curPos = framePositions.get(cat.name());
				frame = new GuiFrame(cat.name(), curPos.getPosX(), curPos.getPosY(), curPos.isExpanded(), Strings.Chinese_HackCategory.split("=")[n]);
			} else {
				frame = new GuiFrame(cat.name(), x, 50, true,Strings.Chinese_HackCategory.split("=")[n]);
			}
			for (Hack m : Core.hackManager.getHacks()) {
				if (cat == m.getCategory()) {
					GuiButton button = new GuiButton(m);
					button.addClickListener(new ClickListener(button));
					button.addExtendListener(new ComponentsListener(button));
					frame.addButton(button);
				}
			}
			addFrame(frame);
			x += 140;
			n++;
		}
		super.initGui();
	}

	public void onGuiClosed() {
		// save positions to framePositions
		if (!getFrames().isEmpty()) {
			for (Frame frame : getFrames()) {
				GuiFrame guiFrame = ((GuiFrame) frame);
				framePositions.put(guiFrame.getTitle(),
						new FramePosition(guiFrame.getPosX(), guiFrame.getPosY(), guiFrame.isExpaned()));
			}
		}
		Core.hackManager.getHack("ClickGui").onDisable();
	}
}
